package cn.cumt.lkk.model;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * Created by lkk on 2015/4/29.
 */
@Entity
@Table(name="link")
public class Link extends BaseObject implements Serializable{
    public static final long serialVersionUID=3617859655330969856L;
    private Long id;
    private String href;
    private String text;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @DocumentId
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(nullable = false,length = 50)
    @Field
    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    @Column(nullable = false ,length = 512)
    @Field
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String toString() {
        return getClass().getName()
                +"[id= "+id
                +",href="+ href
                +",text="+text
                +"]";
    }

    @Override
    public boolean equals(Object o) {
        if(o==null)
            return false;
        if(this==o)
            return true;
        if(o.getClass()!=this.getClass())
            return false;
        Link other=(Link)o;
        return Objects.equals(this.id,other.id)
                &&Objects.equals(this.href,other.href)
                &&Objects.equals(this.text,other.text);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id,href,text);
    }
}
